package guoanmaker.operator.business.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorCoupons;
import guoanmaker.operator.business.service.OperatorCouponsService;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_COUPONS)
public class OperatorCouponsController {

	@Resource
	private  OperatorCouponsService   operatorCouponsService;
	
	
	@Resource
	private AjaxJson ajaxJson;
	
	
	
	/**
	 * 
	 * @param page
	 * @param size
	 * @param couponsname
	 * @param status
	 * @param startTime
	 * @param endTime
	 * @param username
	 * @return
	 */
	@ApiOperation(value = "查询优惠券列表包括多条件查询")
	@RequestMapping(value ="operatorCouponsList",method = RequestMethod.POST)
	public AjaxJson operatorCouponsList(Integer page,Integer size,String couponsname,String username,Integer status,String startTime,String endTime){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.operatorCouponsList(page,size,couponsname,username,status,startTime,endTime));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	/**
	 * 
	 * @param operatorCoupons
	 * @param userid
	 * @return
	 */
	@ApiOperation(value = "新增优惠券")
	@RequestMapping(value ="addCoupons",method = RequestMethod.POST)
	public AjaxJson addCoupons(@RequestBody OperatorCoupons operatorCoupons,String userid,String id,Integer status){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.addCoupons(operatorCoupons,userid,id,status));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "查看优惠券信息")
	@RequestMapping(value ="findbyCouponinfo",method = RequestMethod.POST)
	public AjaxJson findbyCouponinfo(String id){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.findbyCouponinfo(id));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "编辑优惠券")
	@RequestMapping(value ="editCoupons",method = RequestMethod.POST)
	public AjaxJson editCoupons(@RequestBody OperatorCoupons operatorCoupons,String id,String userid){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.editCoupons(id,operatorCoupons,userid));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "删除优惠券")
	@RequestMapping(value ="deleteCoupons",method = RequestMethod.POST)
	public AjaxJson deleteCoupons(String id){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.deleteCoupons(id));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "优惠券统计发送多少张  成本多少，已用多少张")
	@RequestMapping(value ="couponstongji",method = RequestMethod.POST)
	public AjaxJson couponstongji(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.couponstongji());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	
	
	@ApiOperation(value = "可用的优惠券列表(抽奖)")
	@RequestMapping(value ="usedConsponList",method = RequestMethod.POST)
	public AjaxJson usedConsponList(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.usedConsponList());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "可用的优惠券列表(累积签到送)")
	@RequestMapping(value ="usedSignConsponList",method = RequestMethod.POST)
	public AjaxJson usedSignConsponList(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.usedSignConsponList());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
/*	@ApiOperation(value = "可用的优惠券列表(连续签到送)")
	@RequestMapping(value ="usedSignconseConsponList",method = RequestMethod.POST)
	public AjaxJson usedSignconseConsponList(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.usedSignconseConsponList());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}*/
	@ApiOperation(value = "可用的发行数量没有限制的优惠券列表")
	@RequestMapping(value ="usedConsponNolimits",method = RequestMethod.POST)
	public AjaxJson usedConsponNolimits(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.usedConsponNolimits());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "二级业务列表")
	@RequestMapping(value ="secondServerClass",method = RequestMethod.POST)
	public AjaxJson secondServerClass(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.secondServerClass());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "按天统计每种券领券情况")
	@RequestMapping(value ="statisticsForDayCoupons",method = RequestMethod.POST)
	public AjaxJson statisticsForDayCoupons(String  startdate,String enddate,String id){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.statisticsForDayCoupons(startdate,enddate,id));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "统计已送多少用户优惠券")
	@RequestMapping(value ="sentUserCoupons",method = RequestMethod.POST)
	public AjaxJson sentUserCoupons(String id){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.sentUserCoupons(id));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	@ApiOperation(value = "统计多少订单关联此优惠券")
	@RequestMapping(value ="sentUserCouponsOrder",method = RequestMethod.POST)
	public AjaxJson sentUserCouponsOrder(String id){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(operatorCouponsService.sentUserCouponsOrder(id));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败").setData("error");
		}
		return ajaxJson;
	}
	
	
	
}
